'''
Mock Processor.
'''
from processors.single_repository_processor import SingleRepositoryProcessor
from processors.scanner_factory import ScannerFactory
from processors.repository_scanner import RepositoryScanner

class MockScannerFactory (ScannerFactory):
    """
    Always return mock scanner.
    """
    def get_scanner(self, repo_type, name):
        """
        Returns Mock Scanner.
        """
        return MockScanner(self._settings, self._storepath, self._oldpath, name)
    
class MockScanner(RepositoryScanner):    
    """
    Mock Scanner - simply assumes one entry - one repository.
    Scans and processes the repository as usual.
    """
    def scan_repo(self, processors, conf):
        """
        Scans repository - in this case it 
        always contains single repository.
        """
        proc = MockRepositoryProcessor(self._settings, \
                                       self._storepath, self._oldpath, conf)
        proc.initialize()
        proc.process()
        processors.append(proc)
        
class MockRepositoryProcessor(SingleRepositoryProcessor):
    """
    Test repository processor - it takes list of changes from 
    changes parameter rather than from actual repository.
    """
    def __init__(self, settings, storepath, oldpath, conf):
        SingleRepositoryProcessor.__init__(self, settings, \
                                           storepath, oldpath, conf)
        self._input_changes = conf['changes']
    
    def _gather_log_info(self):
        """
        Of course takes logs from the list of changes.
        """
        for i in self._input_changes:
            self._append_change_info(i)
